<?php
class CSession
{
	protected static $current;
	public $id;

	public static function getInstance() {
	  return self::$current;
	}

	public static function setInstance($current) {
	  self::$current = $current;
	}

	function __construct() {
		session_start();
		setcookie("PHPSESSID", session_id(), 0, "/", COOKIE_URL);
		$this->id = session_id();
	}

	function get($name) {
		if(isset($_SESSION[$name])) {
			return $_SESSION[$name];
		}
	}

	function set($name, $value) {
		$_SESSION[$name] = $value;
	}

	function delete($name) {
		unset($_SESSION[$name]);
	}

	function close() {
	}
}

function session($name = false, $value = NULL) {
  $session = CSession::getInstance();
	if($name) {
		if($value === NULL) {
			$value = $session->get($name);
		} else {
			$session->set($name, $value);
		}
		return $value;
	}
	return $session;
}

function cookie($name, $value = NULL) {
	if($value === NULL) {
		return isset($_COOKIE[$name])?$_COOKIE[$name]:'';
	} else {
		return setcookie($name, $value, time()+3600, '/',COOKIE_URL);
	}
}
?>